package _1命令模式;

interface Commend{
    void executeCommend();
}

class Invoker {
    Commend commend; // 存储具体命令引用

    Invoker(Commend commend) {this.commend = commend;}

    public void executeCommend() {
        this.commend.executeCommend();
    }
}

class ConcreteCommend implements Commend{
    Receiver receiver;  // 存储命令接收者引用

    ConcreteCommend(Receiver receiver) { this.receiver = receiver; }

    @Override
    public void executeCommend() {
        receiver.sneakAttack();
    }
}

class Receiver {
    public void sneakAttack() {
        System.out.println("收到命令，保证完成任务！");
    }
}

public class Demo {

    public static void main(String[] args) {
        Receiver receiver = new Receiver();
        ConcreteCommend concreteCommend = new ConcreteCommend(receiver);
        Invoker invoker = new Invoker(concreteCommend);
        invoker.executeCommend();
    }
}


